package com.imooc.ecommerce.service;

import brave.Tracer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 使用代码更直观的看到Sleuth生成的相关跟踪信息
 * @Author: zhangshao
 * @Since: 2023/12/15 15:19
 */
@Slf4j
@Service
public class SleuthTraceInfoService {

	/**
	 * brave.tracer
	 */
	@Autowired
	private Tracer tracer;

	/**
	 * 打印当前的跟踪信息到日志中
	 */
	public void logCurrentTraceInfo(){

		log.info("Sleuth trace id :[{}]",tracer.currentSpan().context().traceId());
		log.info("Sleuth span id :[{}]",tracer.currentSpan().context().spanId());

	}

}
